package com.springmvc.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springmvc.demo.mapper.PermissonMapper;
import com.springmvc.demo.model.RolePermission;
import com.springmvc.demo.service.PermissionService;
@Service
public class PermissionServiceImpl implements PermissionService{
	@Autowired
	PermissonMapper permissionMapper;
	
	@Override
	public boolean hasPermit(String roleid, String permission) {
		// TODO Auto-generated method stub
		RolePermission tempEntity=new RolePermission();
		tempEntity.setRoleid(roleid);
		tempEntity.setPermission(permission);
		RolePermission rolePermission=permissionMapper.selectOne(tempEntity);
		if(rolePermission!=null)
			return true;
		else
			return false;
	}

	@Override
	public String addPermissionToRole(RolePermission rolePermission) {
		// TODO Auto-generated method stub
		int i=permissionMapper.insert(rolePermission);
		if(i>0)
			return "成功";
		else
			return "失败";		
	}

	@Override
	public String deletePermission(RolePermission rolePermission) {
		// TODO Auto-generated method stub
		RolePermission tempEntity=permissionMapper.selectOne(rolePermission);
		int i=permissionMapper.deleteById(tempEntity.getId());
		if(i>0)
			return "成功";
		else
			return "失败";	
	}

}
